//
//  EHPresentationController.m
//  SYBaseProject
//
//  Created by SY on 2025/6/19.
//  Copyright © 2025 YYB. All rights reserved.
//

#import "EHPresentationController.h"
#import <objc/runtime.h>

@implementation EHPresentationController

- (void)containerViewWillLayoutSubviews {
    [super containerViewWillLayoutSubviews];
    
    self.presentedView.frame = self.presentedFrame;
    [self setupCoverView];
}

- (void)setupCoverView {
    if (!_coverView && self.containerView) {
        _coverView = [[UIView alloc] initWithFrame:self.containerView.bounds];
        _coverView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        [self.containerView insertSubview:_coverView atIndex:0];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                                     initWithTarget:self
                                     action:@selector(coverViewTapped)];
        [_coverView addGestureRecognizer:tap];
    }
}

- (void)coverViewTapped {
    [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}

@end

